package jjn.kamacoder.case10;

import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/8/29 23:34
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int m = sc.nextInt();
            int k = sc.nextInt();
            if (m == 0 && k == 0) break;
            int rest = 0;
            int d = m;
            while (d >= k) {
                rest += d / k;
                d = d / k + d % k;
            }
            System.out.println(m + rest);
        }
    }
}
